home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gnome-core.idb / usr / freeware / bin / gnome-convert.z / gnome-convert
Text File  |  2002-07-08  |  3KB  |  134 lines

  1. #!/usr/bin/perl
  2.  
  3. sub basicescape {
  4.     s#&#&apm;#g;
  5.     s#<#<#g;
  6.     s#>#>#g;
  7. }
  8.  
  9. sub tagify {
  10.     s#(^<.*)#<I><$1</I>#;
  11.     s#([a-z]*://\S*)#<A HREF="$1">$1</A>#g;
  12.     s#([-a-zA-Z._0-9]+\@[-a-zA-Z._0-9]+)#<A HREF="mailto:$1">$1</A>#g;
  13.     s#<(\S+\.h)>#<A HREF="file:/usr/include/$1"><$1></A>#g;
  14.     s# (/[a-z]+/[a-z.-/]+)# <A HREF="file:$1">$1</A>#g;
  15. }
  16.  
  17. sub plain {
  18. }
  19.  
  20. $_ = $ARGV[1];
  21. if (/^text.html/) {
  22. } else {
  23.     print "Can't convert to something else than text/html... yet.\n";
  24.     exit(1);
  25. }    
  26.  
  27. $_ = $ARGV[0];
  28. if (/^text.plain/) {
  29.     print "<HTML><BODY>\n";
  30.     print "<PRE>";
  31.     while( <STDIN> ) {
  32.     basicescape();
  33.     tagify();
  34.     print "$_";
  35.     }
  36.     print "</PRE>";
  37.     goto done;
  38.  
  39. if (/^internal.lynx-news/) {
  40.     while( <STDIN> ) {
  41.     if (/<XMP>/) {
  42.         print "<HTML><HEAD><TITLE>News article</TITLE></HEAD><BODY><PRE>";
  43.         last;
  44.     }
  45.     print "$_";
  46.     }
  47.     $first = 1;
  48.     $skip = 0;
  49.     while( <STDIN> ) {
  50.     if ($skip) { $skip--; next; }
  51.     $first = 0;
  52.  
  53.     basicescape();
  54.         s:>+(\S+\@[-a-zA-Z._0-9]*):<A HREF=\"mailto\:$1\">$1</A>:;
  55.     s#From:(.*)#<B>From:$1</B>#;
  56.     s#Subject:(.*)#<B>Subject:$1</B>#;
  57.         s#(\S+\@[-a-zA-Z._0-9]*)#<A HREF="mailto:$1">$1</A>#;
  58.     if (/^Mime-Version/) { next; }
  59.     if (/^Message-ID/) { next; }
  60.     if (/^NNTP-Posting-Host/) { next; }
  61.     if (/^Content-Type/) { next; }
  62.     if (/^Lines/) { next; }
  63.     if (/^Newsgroups/) { 
  64.         s#([a-zA-Z]*\.[a-zA-Z.]*)#<A HREF="$1">$1</A>#g;
  65.     }
  66.     if (/^Path/) { $skip = 1; next; }
  67.  
  68.     if (/^\s*$/) { print "\n\n"; last; }
  69.     print "$_";
  70.     }
  71.     while( <STDIN> ) {
  72.     basicescape();
  73.     tagify();
  74.     s#</XMP>#</PRE>#;
  75.     print "$_";
  76.     }
  77.     goto done;
  78. }
  79.  
  80. if (/^internal.hexdump/) {
  81.     print "<h1>Hexdump</h1>\n";
  82.     print "<pre>\n";
  83.     open( INPUT, 'od -A x -t xC |' );
  84.     while ( <INPUT> ) {
  85.     print $_;
  86.     }
  87.     goto done;
  88. }
  89.  
  90.  
  91. $filename = $ARGV[2];
  92. $filename =~ s#.*/##;
  93. $tmpname = `mktemp /tmp/$filename.conv.XXXXXX`;
  94. $filetype = $_;
  95.  
  96. open( INPUT, "cat > $tmpname |" );
  97. while ( <INPUT> ) {
  98.     print $_;
  99. }
  100.  
  101. $_ = $filetype;
  102. if (/^application.postscript/) {
  103.     print "<h1>Postscript</h1>\n";
  104.     print "<p>External application <tt>gv $tmpname</tt> was called for you. Press <i>back</i> when you are done.\n";
  105.  
  106.     system( "gv $tmpname &" );
  107.     goto done;
  108. }
  109.  
  110. if (/^application.pdf/) {
  111.     print "<h1>Pdf</h1>\n";
  112.     print "<p>External application <tt>gv $tmpname</tt> was called for you. Press <i>back</i> when you are done.\n";
  113.  
  114.     system( "gv $tmpname &" );
  115.     goto done;
  116. }
  117.  
  118. print "<h1>Unknown data type</h1>\n";
  119. print "<p>File with unkown type <TT>$_</TT> was encountered. If it can reasonably be converted to text/html, add conversion routine to <CODE>gnome-convert</CODE> script.\n";
  120. print "<p>File has been saved into <TT>$tmpname</TT>, delete it if you don't need it.\n";
  121.  
  122. print "<p>Additionaly, you may\n<ul>\n";
  123. print "<li><A HREF=\"(text/plain)file:$tmpname\">View it as text</A>\n";
  124. print "<li><A HREF=\"(text/html)file:$tmpname\">View it as html</A>\n";
  125. print "<li><A HREF=\"(internal/hexdump)file:$tmpname\">View it as hexdump</A>\n";
  126. print "</ul>";
  127.  
  128. $type = `file $tmpname`;
  129. print "<p>PS: file's type seems to be: <pre>$type</pre>\n";
  130.  
  131. done:
  132. print "<HR><P ALIGN=right><I>[$ARGV[2]: $ARGV[0] -> $ARGV[1]]</I></BODY></HTML>";
  133.